
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "Boolean.h"
#include "Number.h"
#include "Object.h"
#include "String.h"

Boolean* Boolean::True = new Boolean(true);
Boolean* Boolean::False = new Boolean(false);

Object* Boolean::prototype = new Object(Boolean::False, Object::prototype,
        new String("Boolean"));

Boolean::Boolean(bool value)
    : m_value(value)
{}

ValueType Boolean::getType() const
{
    return VT_BOOLEAN;
}

Boolean* Boolean::toBoolean()
{
    return this;
}

Object* Boolean::toObject()
{
    return new Object(this, Boolean::prototype, new String("Boolean"));
}

String* Boolean::toString()
{
    return new String(m_value ? "true" : "false");
}

Number* Boolean::toNumber()
{
    return new Number(m_value ? 1 : 0);
}

bool Boolean::isTrue() const
{
    return m_value;
}

Boolean* Boolean::equals(Boolean* lhs, Boolean* rhs)
{
    return (lhs->m_value == rhs->m_value) ? Boolean::True : Boolean::False;
}

